import { BadRequestException, ParseIntPipe } from '@nestjs/common';
import * as crypto from 'crypto';

export function md5(str) {
    const hash = crypto.createHash('md5');
    hash.update(str);
    return hash.digest('hex');
}

export function copyProperties(source: object, target: object) {
    const sourceKeys = Object.keys(source);
    const targetKeys = Object.keys(target);
    console.log(sourceKeys, targetKeys);
    for (const key of sourceKeys) {
        if (targetKeys.includes(key)) {
            target[key] = source[key];
        }
    }
}

export function generateParseIntPipe(name: string) {
    return new ParseIntPipe({
        exceptionFactory() {
            throw new BadRequestException(name + ' 应该传数字')
        }
    })
}
